#!/bin/bash

set -ex
if [ ! -e kubevirt ]; then
   echo "clone kubevirt ..."
   git clone --branch v1.4.0 https://gitee.com/jianchwa/kubevirt.git
fi
cd kubevirt
if [[ ! -f ./patch_flag ]];then
  cat ../patches.conf | while read line
  do
      if [[ $line == '' || $line =~ ^\s*# ]]; then
          continue
      fi
      echo "====patch $line======"
      patch -p1 < ../$line
  done
  touch ./patch_flag
else
  echo "patched!"
fi
if [ ! -e libguestfs-appliance-1.48.4-qcow2-linux-5.14.0-183-centos9.tar.xz ]; then
   wget https://github.com/Huang-zic/libguestfs-appliance/releases/download/1.48.4/libguestfs-appliance-1.48.4-qcow2-linux-5.14.0-183-centos9.tar.xz
   tar -xzvf libguestfs-appliance-1.48.4-qcow2-linux-5.14.0-183-centos9.tar.xz
   echo "download libguestfs-appliance success"
fi